
function addRow() {
    const table = document.getElementById("dataTable").getElementsByTagName('tbody')[0];
    const newRow = table.insertRow();

    const nameCell = newRow.insertCell(0);
    nameCell.textContent = "未命名";

    const contactCell = newRow.insertCell(1);
    contactCell.textContent = "无联系方式";

    const actionCell = newRow.insertCell(2);
    actionCell.innerHTML = `<button onclick="editRow(this)">编辑</button>
                            <button onclick="deleteRow(this)">删除</button>`;
}

function editRow(button) {
    const row = button.parentNode.parentNode;
    const nameCell = row.cells[0];
    const contactCell = row.cells[1];

    const newName = prompt("请输入新的姓名：", nameCell.textContent);
    const newContact = prompt("请输入新的联系方式：", contactCell.textContent);

    if (newName !== null) nameCell.textContent = newName;
    if (newContact !== null) contactCell.textContent = newContact;
}


function deleteRow(button) {
    const row = button.parentNode.parentNode;
    row.parentNode.removeChild(row);
}
